package com.handydata.antifraud.web;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.handydata.antifraud.bo.orderbaseinfo.EnterLetterDetailQueryReqBO;
import com.handydata.antifraud.bo.orderbaseinfo.EnterLetterDetailQueryResBO;
import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoReqBO;
import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoResBO;
import com.handydata.antifraud.bo.orderbaseinfo.QueryOrderListReqBO;
import com.handydata.antifraud.bo.orderbaseinfo.QueryOrderListResBO;
import com.handydata.antifraud.common.exception.OrderBaseInfoExCode;
import com.handydata.antifraud.service.OrderBaseInfoService;
import com.handydata.antifraud.vo.datacalllogs.DataCallLogsBeanExtVO;
import com.handydata.antifraud.vo.orderbaseinfo.CreateOrderBaseInfoReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.CreateOrderBaseInfoResVO;
import com.handydata.antifraud.vo.orderbaseinfo.DeleteOrderBaseInfoReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.DeleteOrderBaseInfoResVO;
import com.handydata.antifraud.vo.orderbaseinfo.EnterLetterDetailQueryReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.EnterLetterDetailQueryResVO;
import com.handydata.antifraud.vo.orderbaseinfo.ModifyOrderBaseInfoReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.ModifyOrderBaseInfoResVO;
import com.handydata.antifraud.vo.orderbaseinfo.OrderBaseInfoBeanVO;
import com.handydata.antifraud.vo.orderbaseinfo.QueryOrderBaseInfoReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.QueryOrderBaseInfoResVO;
import com.handydata.antifraud.vo.orderbaseinfo.QueryOrderListBeanVO;
import com.handydata.antifraud.vo.orderbaseinfo.QueryOrderListReqVO;
import com.handydata.antifraud.vo.orderbaseinfo.QueryOrderListResVO;
import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

@RequestMapping("/orderbaseinfo")
@RestController
public class OrderBaseInfoController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(OrderBaseInfoController.class);
	
	@Autowired
	private OrderBaseInfoService orderBaseInfoService;
	
	@ApiOperation(value="新增订单基础信息表", notes="新增订单基础信息表")
	@ApiImplicitParam(name = "req", value = "新增订单基础信息表请求对象", required = true, dataType = "CreateOrderBaseInfoReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateOrderBaseInfoResVO createOrderBaseInfo(@RequestBody CreateOrderBaseInfoReqVO req) {
		try {
			logger.info("Execute createOrderBaseInfo, param is {}", req);
			OrderBaseInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderBaseInfoReqBO.class);
			OrderBaseInfoResBO resBO = orderBaseInfoService.createOrderBaseInfo(reqBO);
			CreateOrderBaseInfoResVO res = CommonBeanConvertor.convert(resBO, CreateOrderBaseInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateOrderBaseInfoResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改订单基础信息表", notes="修改订单基础信息表")
	@ApiImplicitParam(name = "req", value = "修改订单基础信息表请求对象", required = true, dataType = "ModifyOrderBaseInfoReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyOrderBaseInfoResVO modifyOrderBaseInfo(@RequestBody ModifyOrderBaseInfoReqVO req) {
		try {
			logger.info("Execute modifyOrderBaseInfo, param is {}", req);
			OrderBaseInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderBaseInfoReqBO.class);
			OrderBaseInfoResBO resBO = orderBaseInfoService.modifyOrderBaseInfo(reqBO);
			ModifyOrderBaseInfoResVO res = CommonBeanConvertor.convert(resBO, ModifyOrderBaseInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyOrderBaseInfoResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除订单基础信息表", notes="删除订单基础信息表")
	@ApiImplicitParam(name = "req", value = "修改订单基础信息表请求对象", required = true, dataType = "DeleteOrderBaseInfoReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteOrderBaseInfoResVO deleteOrderBaseInfo(@RequestBody DeleteOrderBaseInfoReqVO req) {
		try {
			logger.info("Execute deleteOrderBaseInfo, param is {}", req);
			OrderBaseInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderBaseInfoReqBO.class);
			OrderBaseInfoResBO resBO = orderBaseInfoService.deleteOrderBaseInfo(reqBO);
			DeleteOrderBaseInfoResVO res = CommonBeanConvertor.convert(resBO, DeleteOrderBaseInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteOrderBaseInfoResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询订单基础信息表", notes="查询订单基础信息表")
	@ApiImplicitParam(name = "req", value = "查询订单基础信息表请求对象", required = true, dataType = "QueryOrderBaseInfoReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryOrderBaseInfoResVO queryOrderBaseInfo(@RequestBody QueryOrderBaseInfoReqVO req) {
		try {
			logger.info("Execute queryOrderBaseInfo, param is {}", req);
			OrderBaseInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderBaseInfoReqBO.class);
			OrderBaseInfoResBO resBO = orderBaseInfoService.queryOrderBaseInfo(reqBO);
			QueryOrderBaseInfoResVO res = CommonBeanConvertor.convert(resBO, QueryOrderBaseInfoResVO.class, OrderBaseInfoBeanVO.class);
			res.setRespCode("0000");
			res.setRespMsg("调用成功");
			return res;
		} catch (Exception e) {
			return handleException(e, QueryOrderBaseInfoResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="业务进件管理列表查询", notes="业务进件管理列表查询")
	@ApiImplicitParam(name = "req", value = "业务进件管理列表查询请求对象", required = true, dataType = "QueryOrderListReqVO", paramType = "body")
	@PostMapping("/queryOrderList")
	public QueryOrderListResVO queryOrderList(@RequestBody QueryOrderListReqVO req) {
		try {
			logger.info("Execute QueryOrderListReqVO, param is {}", req);
			QueryOrderListReqBO reqBO = CommonBeanConvertor.convert(req, QueryOrderListReqBO.class);
			QueryOrderListResBO resBO = orderBaseInfoService.queryOrderList(reqBO);
			QueryOrderListResVO res = CommonBeanConvertor.convert(resBO, QueryOrderListResVO.class, QueryOrderListBeanVO.class);
			res.setRespCode("0000");
			res.setRespMsg("调用成功");
			return res;
		} catch (Exception e) {
			return handleException(e, QueryOrderListResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="业务进件详情查询", notes="业务进件详情查询")
	@ApiImplicitParam(name = "req", value = "业务进件详情查询请求对象", required = true, dataType = "QueryOrderListReqVO", paramType = "body")
	@PostMapping("/enterLetterDetailQuery")
	public EnterLetterDetailQueryResVO enterLetterDetailQuery(@RequestBody EnterLetterDetailQueryReqVO req) { 
		EnterLetterDetailQueryResVO res = new EnterLetterDetailQueryResVO();
		try {
			logger.info("Execute QueryOrderListReqVO, param is {}", req);
			EnterLetterDetailQueryReqBO reqBO = CommonBeanConvertor.convert(req, EnterLetterDetailQueryReqBO.class);
			EnterLetterDetailQueryResBO resBO = orderBaseInfoService.enterLetterDetailQuery(reqBO);
			res = CommonBeanConvertor.convert(resBO, EnterLetterDetailQueryResVO.class, DataCallLogsBeanExtVO.class);
			res.setRespCode("0000");
			res.setRespMsg("调用成功");
		} catch (Exception e) {
			res = handleException(e, EnterLetterDetailQueryResVO.class, req, OrderBaseInfoExCode.SYS_UNKNOWN_ERROR);
		}
		return res;
	}
	
}
